package com.sds.sweng.swat.miplatform.ui.design.support;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;

public abstract class TextChangeListener implements Listener {

	public static void addTextChangeListener(Text text, TextChangeListener textChangeListener) {
		text.addListener(SWT.KeyUp, textChangeListener);
		text.addListener(SWT.FocusOut, textChangeListener);
	}

	@Override
	public void handleEvent(Event event) {
		if (event.type == SWT.FocusOut)
			onTextChanged(event);
		else if (event.type == SWT.KeyUp) {
			if (event.character == SWT.CR)
				onTextChanged(event);
		}
	}

	public abstract void onTextChanged(Event event);

}
